package com.max.spark.utils

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SparkSession

object SparkUtil {

  /**
   * 获取sparkConf
   * @param master
   * @param appName
   * @return
   */
    def conf(master: String = "local[*]", appName: String = "app"): SparkConf = {
      new SparkConf().setMaster(master).setAppName(appName)
    }

  /**
   * 获取sparkContext
   * @param conf
   * @return
   */
    def sparkContext(sparkConf: SparkConf = conf()): SparkContext = new SparkContext(sparkConf)

  /**
   * 获取sparkSession
   * @param conf
   * @return
   */
    def sparkSession(sparkConf: SparkConf = conf()): SparkSession = {
      SparkSession.builder().config(sparkConf).getOrCreate()
    }
}
